package com.innotek.testworkstation.common.restassured.apipage;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

/**
 * @ClassName PageModel
 * @Description 接口数据驱动基类
 * @Author wangx
 * @Date 2020/1/6 17:11
 * @Version 1.0
 **/

public class PageModel {
    /**
     * 项目， web表示后台，pos表示POS机
     */
    public String project;
    /**
     * 页面/模块名字，对应用例里的page属性
     */
    public String page;
    /**
     * page下的所有接口
     */
    public HashMap<String, ApiModel> actions;

    /**
     * 支持从yaml中读取
     * @param path yaml页面接口文件的路径
     */
    public static PageModel loadApi(String path) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
        return objectMapper.readValue(new File(path), PageModel.class);
    }

}
